package com.leeon.container.example.collection;

import typeinfo.pets.Pet;
import typeinfo.pets.Pets;

import java.util.Collection;
import java.util.Iterator;

public class Example30 implements Collection<Pet> {

    private Pet[] pets = Pets.createArray(10);

    @Override
    public int size() {
        return pets.length;
    }

    @Override
    public boolean isEmpty() {
        return pets.length > 0 ? true : false;
    }

    @Override
    public boolean contains(Object o) {
        if(o == null || !(o instanceof Pet)){
            return false;
        }
        Pet pet = (Pet)o;
        for (Pet p : pets) {
            if(p.equals(pet)){
                return true;
            }
        }
        return false;
    }

    @Override
    public Iterator<Pet> iterator() {
        return new Iterator<Pet>() {

            private int index = 0;

            @Override
            public boolean hasNext() {
                return index < pets.length;
            }

            @Override
            public Pet next() {
                return pets[index++];
            }

            @Override
            public void remove(){
            }
        };
    }

    @Override
    public Object[] toArray() {
        return pets;
    }

    @Override
    public <T> T[] toArray(T[] a) {
        return null;
    }

    @Override
    public boolean add(Pet pet) {
        return false;
    }

    @Override
    public boolean remove(Object o) {
        return false;
    }

    @Override
    public boolean containsAll(Collection<?> c) {
        return false;
    }

    @Override
    public boolean addAll(Collection<? extends Pet> c) {
        return false;
    }

    @Override
    public boolean removeAll(Collection<?> c) {
        return false;
    }

    @Override
    public boolean retainAll(Collection<?> c) {
        return false;
    }

    @Override
    public void clear() {

    }
}
